import QtQuick
import QtQuick.Controls
import QtQuick.Layouts

import WubiMem

Window {
    width: 1200
    height: 900
    minimumWidth: width
    minimumHeight: height
    maximumWidth: width
    maximumHeight: height
    visible: true
    title: qsTr("WubiMem")

    Wubi86Query {
        id: wubi86query
    }

    property var code_to_location: {
        "a": {x=110, y=305},
        "b": {x=550, y=460},
        "c": {x=330, y=460},
        "d": {x=330, y=305},
        "e": {x=330, y=160},
        "f": {x=440, y=305},
        "g": {x=550, y=305},
        "h": {x=660, y=305},
        "i": {x=880, y=160},
        "j": {x=770, y=305},
        "k": {x=880, y=305},
        "l": {x=990, y=305},
        "m": {x=770, y=460},
        "n": {x=660, y=460},
        "o": {x=990, y=160},
        "p": {x=1100, y=160},
        "q": {x=110, y=160},
        "r": {x=440, y=160},
        "s": {x=220, y=305},
        "t": {x=550, y=160},
        "u": {x=770, y=160},
        "v": {x=440, y=460},
        "w": {x=220, y=160},
        "x": {x=220, y=460},
        "y": {x=660, y=160},
        "z": {x=110, y=460},
    }

    ColumnLayout {
        anchors.fill:parent
        TextField {
            font.pointSize: 12
            Layout.preferredWidth: 180
            placeholderText:'输入要反查的汉字...'

            onEditingFinished: {
                wubi86query.query = text

                var codes = wubi86query.codes
                console.log("codes=", codes)

                if (codes.length > 0 && codes[0]) {
                    console.log("codes0 ", codes[0])
                    mask0._x = code_to_location[codes[0]].x
                    mask0._y = code_to_location[codes[0]].y
                    mask0._text = '0'
                    mask0._visible = true
                }
                else {
                    mask0._visible = false
                }

                if (codes.length > 0 && codes[1]) {
                    console.log("codes1 ", codes[1])
                    mask1._x = code_to_location[codes[1]].x
                    mask1._y = code_to_location[codes[1]].y
                    mask1._text = '1'
                    mask1._visible = true
                }
                else {
                    mask1._visible = false
                }

                if (codes.length > 0 && codes[2]) {
                    console.log("codes2 ", codes[2])
                    mask2._x = code_to_location[codes[2]].x
                    mask2._y = code_to_location[codes[2]].y
                    mask2._text = '2'
                    mask2._visible = true
                }
                else {
                    mask2._visible = false
                }

                if (codes.length > 0 && codes[3]) {
                    console.log("codes3 ", codes[3])
                    mask3._x = code_to_location[codes[3]].x
                    mask3._y = code_to_location[codes[3]].y
                    mask3._text = '3'
                    mask3._visible = true
                }
                else {
                    mask3._visible = false
                }
            }
        }

        Label {
            font.pointSize: 12
            text: '字根......' + wubi86query.roots
        }

        Label {
            font.pointSize: 12
            text: '键码......' + wubi86query.codes
        }

        Image {
            source: "./res/wubi_zigen_table.jpg"

            KeyMask {
                id: mask0
                _x:100
                _y:100
                _text: '0'
                _visible:false
            }

            KeyMask {
                id: mask1
                _x:100
                _y:100
                _text: '1'
                _visible:false
            }

            KeyMask {
                id: mask2
                _x:100
                _y:100
                _text: '2'
                _visible:false
            }

            KeyMask {
                id: mask3
                _x:100
                _y:100
                _text: '3'
                _visible:false
            }
        }
    }
}
